package online.rainy.dbhomework;

import online.rainy.dbhomework.dao.CourseDao;
import online.rainy.dbhomework.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "IndexServlet", value = "/")
public class IndexServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("text/html");
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        CourseDao mapper = sqlSession.getMapper(CourseDao.class);
        request.setAttribute("result", mapper.getCourses());
        request.getRequestDispatcher("/jsp/index.jsp").forward(request, response);
    }
}